baseUrl="";
var Plima={};
Plima.pgrid=function(cfg){
		Ext.apply(this,cfg);
		this.ds=new Ext.data.Store({
							  proxy:new Ext.data.HttpProxy({
									url:this.url
									}),
							  reader:new Ext.data.JsonReader({
									root:'results',
									totalProperty:'total'
									},[
									  {name:'order_id',mapping:'o_increment_id'},
									   {name:'product_name',mapping:'o_increment_product'},
									   {name:'client_name',mapping:'o_client_name'},
									   {name:'client_address',mapping:'o_client_address'},
									   {name:'order_time',mapping:'o_increment_date'},
									   {name:'order_status',mapping:'o_increment_status'},
									   {name:'telephone',mapping:'o_client_telephone'},
									   {name:'country_id',mapping:'o_client_country'}
									   ])
	});		
	
	this.cm=new Ext.grid.ColumnModel([
									 //new Ext.grid.CheckboxSelectionModel({singleSelect:false}),
									 
									 {id:'increment_id',header:'订单号',dataIndex:'order_id',width:70},
									 {header:'时间',dataIndex:'order_time',width:70,renderer:show_date},
									 {header:'状态',dataIndex:'order_status',width:60,renderer:show_status},
									 {header:'客户',dataIndex:'client_name',width:60},
									 {header:'地址',dataIndex:'client_address',width:150}									 
	]);
	  //定义分页条栏				 
	this.pagBar=new Ext.PagingToolbar({
										pageSize:10,
										store:this.ds,
										displayInfo:true,
										displayMsg:'第{0}到{1}条产品 共{2}条产品',
										emptyMsg:'no content',
										items:['-','每页显示条记录','-']
									 });

	  this.cm.defaultSortable = true;
	  this.grid=new Ext.grid.GridPanel({
										  autowidht		: true,
										  autoHeight	: true,
										  store			: this.ds,
										  cm			: this.cm,
										  loadMask		: true,
										  labelAlign	: "right",
										  forceFit  	: true 
										  });
	  
	this.ds.load({params:{start:0,limit:10}});
	Plima.pgrid.superclass.constructor.call(this,{																								
												autoHeight	: true																								
												});
		
		
	}



Plima.win_user=function(cfg){
		Ext.apply(this,cfg);
		this.form=new Ext.form.FormPanel({
		labelAlign:'top',
		frame:true,
		plain:true,
		buttonAlign : 'center',  
		bodyStyle:'padding:5px',
		autowidht:true,
		autoHeight:true,
		items:[{
			   layout:'column',
			   border:false,
			   items:[{
			   		columnWidth:.5,
					layout:'form',
					border:false,
					items:[{
						   xtype:'textfield',
						   fieldLabel:'真实姓名',
						   name:'realname',
						   anchor:'80%',
						   allowBlank:false
						   },
						   {
						   xtype:'textfield',
						   fieldLabel:'密码',
						   name:'pwd1',
						   inputType : 'password',
						   anchor:'80%',
						   allowBlank:false
						   },
						   {
						   xtype:'textfield',
						   fieldLabel:'邮箱',
						   name:'email',
						   value:'2@2.com',
						   anchor:'80%',
						   allowBlank:false,
						   vtype:'email'
						   }]
					  },
					  {
			   		columnWidth:.5,
					layout:'form',
					border:false,
					items:[{
						   xtype:'textfield',
						   fieldLabel:'登录名',
						   name:'username',
						   anchor:'80%',
						   allowBlank:false
						   },
						   {
						   xtype:'textfield',
						   fieldLabel:'重复密码',
						   name:'pwd2',
						   inputType : 'password',
						   anchor:'80%'
						   }]
					  }]			   
			   }]
										 });

	Plima.win_user.superclass.constructor.call(this,{				
											    resizable	: true,
												width		: 500,	
												autoHeight	: true,
												items		: [this.form],
												buttonAlign	: 'center'												
												});
		
		
	}

Ext.extend(Plima.pgrid,Ext.grid.GridPanel);
Ext.extend(Plima.win_user,Ext.Window);


Ext.ux.ThemeCycleButton = Ext.extend(Ext.CycleButton, {



	/**

	 * file 你的css名称

	 * text 下拉框的名称

	 * iconCls 设置图标css

	 */									 

	cssItems:[

		{file: 'ext-all.css', text: '蓝色月影&nbsp;',checked:true,  iconCls: 'icon-blue-theme'},

		{file: 'xtheme-gray.css', text: '灰色回忆&nbsp;', iconCls: 'icon-gray-theme'},

		{file: 'xtheme-slate.css', text: '深蓝心情&nbsp;', iconCls: 'icon-blue-theme'},

		{file: 'xtheme-pink.css', text: '娇艳绯红&nbsp;', iconCls: 'icon-blue-theme'},

		{file: 'xtheme-olive.css', text: '绿色芳香&nbsp;', iconCls: 'icon-blue-theme'},

		{file: 'xtheme-purple.css', text: '诱惑紫色&nbsp;', iconCls: 'icon-blue-theme'}
		

	],

	themeVar:'style',

	headVar: 'head',

	//cssPath是你放css的位置，这个路径要是弄错了，神仙也出不来的

	cssPath:baseUrl+'/public/css/',

	

	initComponent: function() {

		Ext.apply(this, {

		    showText: true,

			prependText: '&nbsp;',

   			items: this.cssItems

		});

		if(Ext.state.Manager){ 

        	var selectedTheme = Ext.state.Manager.get(this.themeVar); 

            if(selectedTheme){ 

				for(var i=0; i<this.items.length;i++){

					if (this.items[i].file == selectedTheme){

						this.items[i].checked = true;

//						this.setActiveItem(this.items[i], true); //error ??

						this.changeHandler(this, this.items[i]);

//						this.changeHandler.defer(1000, this, [this, this.items[i]]);

						break;

					}

				}

            } 

        }

		Ext.ux.ThemeCycleButton.superclass.initComponent.apply(this, arguments);

	},

	

	changeHandler: function(o, i){

        if(Ext.state.Manager.getProvider()) {

            Ext.state.Manager.set(this.themeVar, i.file);

			Ext.state.Manager.set(this.headVar, i.head);

        }

		Ext.util.CSS.swapStyleSheet(this.themeVar, this.cssPath + i.file);

		Ext.util.CSS.getRule('.x-panel-body', true).style.background = 'url(' + i.head + ')';

//		Ext.util.CSS.updateRule('.x-panel-body', 'background', 'url(' + i.head + ')');

		if(Ext.getCmp('viewport')){

   	    	Ext.getCmp('viewport').layout.center.panel.setSize(Ext.getCmp('viewport').layout.center.getSize().width + 1);

			Ext.getCmp('viewport').doLayout();

			Ext.getCmp('viewport').layout.center.panel.setSize(Ext.getCmp('viewport').layout.center.getSize().width - 1);

			Ext.getCmp('viewport').doLayout();

		}

	}

	        

});



Ext.reg('themecyclebutton', Ext.ux.ThemeCycleButton);




function show_link(val){
	return "<a href='"+val+"' target='_blank'>"+val+"</a>";
}
function show_money(val){
	if(parseInt(val)===0 || val===null){
		return "<span style='color:red'>"+val+"</span>";
	}
	return "$"+val+" USD";
}
function show_img(val){
	//return "<span style='display:table' qtip='<img src=\'<?=$this->website?>/media/catalog/product/"+val+"\''>"+val+"</span>";	
	//var link='<?=$this->website?>/media/catalog/product/'+val;
	return "<a href='"+link+"' class='lb-flower'><img src='"+link+"' width='50' height='30' /></a>";
}

function show_check_status(val){
	var iconsPath=baseUrl+"/public/images/icons";
	return val==="1"?"<img src='"+iconsPath+"/tick.gif'>":"<img src='"+iconsPath+"/cancel.png'>";
	}

function show_status(val){
	switch(val){
		case "pending":
			return "等待中";
			break;
		case "processing":
			return "处理中";
			break;
		case "hold":
			return "等待确认";
			break;
		case "pending_pament":
			return "等待付款";
			break;
		case "holded":
			return "OK";
			break;
		case "pending_paypal":
			return "等待paypal";
			break;
		case "canceled":
			return "取消";
			break;
		default:
			return "未知状态";
			break;		
		}	
}



function show_email(val){
	return "<a href='mailto:"+val+"'>"+val+"</a>";
	}
	
function changeSkin(name){
Ext.util.CSS.swapStyleSheet("theme","/smartytest/work/public/css/"+name);
var cp = new Ext.state.CookieProvider();
Ext.state.Manager.setProvider(cp);
cp.set('skin',name);
}

function show_date(val){
	position=val.indexOf(" ");
	val=val.substring(0,position);
	if(val==today){
		return "<font color='red'>"+val+"</font>";		
		}
	else{
		return val;
		}
	}

function show_content(val){
	return val.substring(0,200)+"..........";
	}




function add_tab(name,link,id){
	var main=Ext.getCmp('content');
	var tabId="tab_"+id;
	var tabLink=link;
	var tabTitle=name;
	var tab=main.getComponent(tabId);
	var subMainId='tab_'+id+'main';
    if(!tab){
        tab=main.add({
				'id':tabId,
				'title':tabTitle,
				closable:true,
				autoScroll : true ,
				layout : 'fit' ,
				border : false
				//autoLoad:{url:tabLink,scripts:true,nocache:true}
				});        
		main.setActiveTab(tab);  
		var loadmask = new Ext.LoadMask(tab.body,{msg:"页面加载中……"}) ;		
		loadmask.show() ;
		tab.load({
			url: tabLink,
			discardUrl: false,
			//nocache: true,
			timeout: 3000,
			scripts: true,
			text:'',
			callback:function(a,b,c){
				if(b){
					loadmask.hide();
					}
				}
		});
    }
	main.setActiveTab(tab);    
}
// vim: ts=4:sw=4:nu:fdc=4:nospell
/**
* Ext.form.MultiSelect, List of Values Combo
*
* @author    Ing. 
* @copyright (c) 2008, by Ing. 
* @date      16. April 2008
* @version   $Id: Ext.form.MultiSelect.js 291 2008-07-03 07:46:49Z jozo $
*
* @license Ext.form.MultiSelect.js is licensed under the terms of the Open Source
* LGPL 3.0 license. Commercial use is permitted to the extent that the 
* code/component(s) do NOT become part of another Open Source or Commercially
* licensed development library or toolkit without explicit permission.
* 
* License details: http://www.gnu.org/licenses/lgpl.html
*/
/*global Ext */
// add RegExp.escape if it has not been already added
if('function' !== typeof RegExp.escape) {
RegExp.escape = function(s) {
   if('string' !== typeof s) {
    return s;
   }
   // Note: if pasting from forum, precede ]/\ with backslash manually
   return s.replace(/([.*+?^=!{}()|[\]\/\\])/g, '\\$1');
}; // eo function escape
}
// create namespace
Ext.ns('Ext.form');
/**
*
* @class Ext.form.MultiSelect
* @extends Ext.form.ComboBox
*/
Ext.form.MultiSelect = Ext.extend(Ext.form.ComboBox, {
// {{{
    // configuration options
/**
* @cfg {String} checkField name of field used to store checked state.
* It is automatically added to existing fields.
* Change it only if it collides with your normal field.
*/
checkField:'checked'
/**
* @cfg {String} separator separator to use between values and texts
*/
    ,separator:','
/**
* @cfg {String/Array} tpl Template for items. 
* Change it only if you know what you are doing.
*/
// }}}
    // {{{
    ,initComponent:function() {
        
   // template with checkbox
   /*if(!this.tpl) {
    this.tpl = 
     '<tpl for=".">'
     +'<div class="x-combo-list-item">'
     +'<img src="' + Ext.BLANK_IMAGE_URL + '" '
     +'class="ux-MultiSelect-icon ux-MultiSelect-icon-'
     +'{[values.' + this.checkField + '?"checked":"unchecked"' + ']}">'
     +'<div class="ux-MultiSelect-item-text">{' + (this.displayField || 'text' )+ '}</div>'
     +'</div>'
     +'</tpl>'
    ;
   }*/if(!this.tpl) {
    this.tpl = 
     '<tpl for=".">'
     +'<div class="x-combo-list-item">'
     +'<img src="' + Ext.BLANK_IMAGE_URL + '" '
     +'class="ux-MultiSelect-icon ux-MultiSelect-icon-'
     +'{[values.' + this.checkField + '?"checked":"unchecked"' + ']}">'
     +'{[values.'+this.displayField+']}'
     +'</div>'
     +'</tpl>'
    ;
   }
        // call parent
        Ext.form.MultiSelect.superclass.initComponent.apply(this, arguments);
   // install internal event handlers
   this.on({
    scope:this
    ,beforequery:this.onBeforeQuery
    ,blur:this.onRealBlur
   });
   // remove selection from input field
   this.onLoad = this.onLoad.createSequence(function() {
    if(this.el) {
     var v = this.el.dom.value;
     this.el.dom.value = '';
     this.el.dom.value = v;
    }
   });
    } // e/o function initComponent
    // }}}
// {{{
/**
* Disables default tab key bahavior
* @private
*/
,initEvents:function() {
   Ext.form.MultiSelect.superclass.initEvents.apply(this, arguments);
   // disable default tab handling - does no good
   this.keyNav.tab = false;
} // eo function initEvents
// }}}
// {{{
/**
* clears value
*/
,clearValue:function() {
   this.value = '';
   this.setRawValue(this.value);
   this.store.clearFilter();
   this.store.each(function(r) {
    r.set(this.checkField, false);
   }, this);
   if(this.hiddenField) {
    this.hiddenField.value = '';
   }
   this.applyEmptyText();
} // eo function clearValue
// }}}
// {{{
/**
* @return {String} separator (plus space) separated list of selected displayFields
* @private
*/
,getCheckedDisplay:function() {
   var re = new RegExp(this.separator, "g");
   return this.getCheckedValue(this.displayField).replace(re, this.separator + ' ');
} // eo function getCheckedDisplay
// }}}
// {{{
/**
* @return {String} separator separated list of selected valueFields
* @private
*/
,getCheckedValue:function(field) {
   field = field || this.valueField;
   var c = [];
   // store may be filtered so get all records
   var snapshot = this.store.snapshot || this.store.data;
   snapshot.each(function(r) {
    if(r.get(this.checkField)) {
     c.push(r.get(field));
    }
   }, this);
   return c.join(this.separator);
} // eo function getCheckedValue
// }}}
// {{{
/**
* beforequery event handler - handles multiple selections
* @param {Object} qe query event
* @private
*/
,onBeforeQuery:function(qe) {
   qe.query = qe.query.replace(new RegExp(RegExp.escape(this.getCheckedDisplay()) + '[ ' + this.separator + ']*'), '');
} // eo function onBeforeQuery
// }}}
// {{{
/**
* blur event handler - runs only when real blur event is fired
*/
,onRealBlur:function() {
   this.list.hide();
   var rv = this.getRawValue();
   var rva = rv.split(new RegExp(RegExp.escape(this.separator) + ' *'));
   var va = [];
   var snapshot = this.store.snapshot || this.store.data;
   // iterate through raw values and records and check/uncheck items
   Ext.each(rva, function(v) {
    snapshot.each(function(r) {
     if(v === r.get(this.displayField)) {
      va.push(r.get(this.valueField));
     }
    }, this);
   }, this);
   this.setValue(va.join(this.separator));
   this.store.clearFilter();
} // eo function onRealBlur
// }}}
// {{{
/**
* Combo's onSelect override
* @private
* @param {Ext.data.Record} record record that has been selected in the list
* @param {Number} index index of selected (clicked) record
*/
,onSelect:function(record, index) {
        if(this.fireEvent('beforeselect', this, record, index) !== false){
    // toggle checked field
    record.set(this.checkField, !record.get(this.checkField));
    // display full list
    if(this.store.isFiltered()) {
     this.doQuery(this.allQuery);
    }
    // set (update) value and fire event
    this.setValue(this.getCheckedValue());
            this.fireEvent('select', this, record, index);
        }
} // eo function onSelect
// }}}
// {{{
/**
* Sets the value of the MultiSelect
* @param {Mixed} v value
*/
,setValue:function(v) {
   if(v) {
    v = '' + v;
    if(this.valueField) {
     this.store.clearFilter();
     this.store.each(function(r) {
      var checked = !(!v.match(
       '(^|' + this.separator + ')' + RegExp.escape(r.get(this.valueField))
       +'(' + this.separator + '|$)'))
      ;
      r.set(this.checkField, checked);
     }, this);
     this.value = this.getCheckedValue();
     this.setRawValue(this.getCheckedDisplay());
     if(this.hiddenField) {
      this.hiddenField.value = this.value;
     }
    }
    else {
     this.value = v;
     this.setRawValue(v);
     if(this.hiddenField) {
      this.hiddenField.value = v;
     }
    }
    if(this.el) {
     this.el.removeClass(this.emptyClass);
    }
   }
   else {
    //this.clearValue();
   }
} // eo function setValue
// }}}
// {{{
/**
* Selects all items
*/
,selectAll:function() {
        this.store.each(function(record){
            // toggle checked field
            record.set(this.checkField, true);
        }, this);
        //display full list
        this.doQuery(this.allQuery);
        this.setValue(this.getCheckedValue());
    } // eo full selectAll
// }}}
// {{{
/**
* Deselects all items. Synonym for clearValue
*/
    ,deselectAll:function() {
   this.clearValue();
    } // eo full deselectAll 
// }}}
}); // eo extend
// register xtype
Ext.reg('multiSelect', Ext.form.MultiSelect);


Ext.namespace('Boat.UI');

//单选下拉框
Boat.UI.SingleSelect = Ext.extend(Ext.form.ComboBox, {
    triggerAction: 'all',
    mode: 'local',
    editable: false,
    emptyText: '请选择...',
    displayField: 'text',
    valueField: 'value',
    /*
    @store 数组数据源 例如:[[1,'a'],[2,'b'],[3,'c']]或['a','b','c']
    */
    initComponent: function() {
        this.hiddenName = this.name;
        Boat.UI.SingleSelect.superclass.initComponent.call(this);
    },

    setValue: function(v) {
        if (Ext.type(v) == 'object') {
            v = v[this.valueField];
        }
        Boat.UI.SingleSelect.superclass.setValue.call(this, v);
    }
});
Ext.reg('select', Boat.UI.SingleSelect);

//多选下拉框
Boat.UI.MultiSelect = Ext.extend(Boat.UI.SingleSelect, {
    tpl: '<div class="multiselect"></div>',

    // private
    initList: function() {
        Boat.UI.MultiSelect.superclass.initList.call(this);
        this.initCheckBox();
    },

    // private
    initCheckBox: function() {
        var ct = this.innerList.first('.multiselect');
        this.items = new Ext.util.MixedCollection();
        var fn = function(r) {
            var c = new Ext.form.Checkbox({
                boxLabel: r.data[this.displayField],
                inputValue: r.data[this.valueField],
                renderTo: ct
            });
            this.items.add(c);
        };
        this.store.each(fn, this);

        this.on('collapse', this.onCollapse, this);
        this.on('expand', this.onExpand, this);
    },

    onCollapse: function() {
        var value = [];
        var fn = function(c) {
            if (c.getValue()) {
                value.push(c.el.dom.value);
            }
        };
        this.items.each(fn);

        this.setValue(value);
    },

    setValue: function(v) {
        if (!Ext.isArray(v)) { v = [v]; }
        this.hiddenField.value = v;
        Ext.form.ComboBox.superclass.setValue.call(this, this.getTexts(v));
        this.value = v;
    },

    getTexts: function(v) {
        var texts = [];
        var fn = function(r) {
            var rv = r.data[this.valueField];

            for (var i = 0; i < v.length; i++) {
                if (rv == v[i]) {
                    texts.push(r.data[this.displayField]);
                    break;
                }
            }
        };
        this.store.each(fn, this);
        return texts.join();
    },

    onExpand: function() {
        if (!Ext.isArray(this.value) || this.value.length == 0) { return; }

        var v = this.value;

        var fn = function(item) {
            var rv = item.el.dom.value;
            item.setValue(false);
            
            for (var i = 0; i < v.length; i++) {
                if (rv == v[i]) {
                    item.setValue(true);
                    break;
                }
            }
        };

        this.items.each(fn);
    }
});
Ext.reg('multiselect', Boat.UI.MultiSelect);